/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package iamutkarshtiwari.github.io.ananas.editimage.utils;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 日志打印工具类
 */
public class LogUtils {

    //region ohos HiLog

    private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000f00, "dqh");

    private static final String LOG_FORMAT = "%{public}s:%{public}s";

    private LogUtils() {

    }

    /**
     * 打印debug日志
     *
     * @param tag String
     * @param msg String
     */
    public static void debug(String tag, String msg) {
        HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg);
    }

    /**
     * 打印info日志
     *
     * @param tag String
     * @param msg String
     */
    public static void info(String tag, String msg) {
        HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg);
    }

    /**
     * 打印info日志
     *
     * @param tag    String
     * @param format String
     * @param args   Object
     */
    public static void info(String tag, final String format, Object... args) {
        String buffMsg = String.format(Locale.ROOT, format, args);
        HiLog.info(LABEL_LOG, LOG_FORMAT, tag, buffMsg);
    }

    /**
     * 打印warn日志
     *
     * @param tag String
     * @param msg String
     */
    public static void warn(String tag, String msg) {
        HiLog.warn(LABEL_LOG, LOG_FORMAT, tag, msg);
    }

    /**
     * 打印error日志
     *
     * @param tag String
     * @param msg String
     */
    public static void error(String tag, String msg) {
        HiLog.error(LABEL_LOG, LOG_FORMAT, tag, msg);
    }

    /**
     * 打印error日志
     *
     * @param tag    String
     * @param format String
     * @param args   Objects
     */
    public static void error(String tag, final String format, Object... args) {
        String buffMsg = String.format(Locale.ROOT, format, args);
        HiLog.error(LABEL_LOG, LOG_FORMAT, tag, buffMsg);
    }

    //endregion

    //region java Logger

    private static Logger logger;

    private static Logger createLogger(String tag) {
        if (logger == null) {
            logger = Logger.getLogger(tag);
        }
        return logger;
    }

    /**
     * 打印SEVERE日志 d
     *
     * @param msg String
     */
    public static void logd(String msg) {
        createLogger("log").log(Level.SEVERE, msg);
    }

    /**
     * 打印SEVERE日志 d
     *
     * @param tag String
     * @param msg String
     */
    public static void logd(String tag, String msg) {
        createLogger(tag).log(Level.SEVERE, msg);
    }

    /**
     * 打印SEVERE日志 e
     *
     * @param msg String
     */
    public static void loge(String msg) {
        createLogger("log").log(Level.SEVERE, msg);
    }

    /**
     * 打印SEVERE日志 e
     *
     * @param tag String
     * @param msg String
     */
    public static void loge(String tag, String msg) {
        createLogger(tag).log(Level.SEVERE, msg);
    }

    //endregion
}
